-- -- -- -- -- -- -- -- -- -- -- --
-- -- ENEMY -- -- -- -- -- -- -- -
-- -- -- -- -- -- -- -- -- -- -- --
--  enemies class
-- load superclass


Enemy = Character:new{speed = 2,
	searchRange = 20,
	exp = 10,
	currentState =  Gameelement.stateList.default,
	experience = 0,
	dmg = 0,
	attackrange = 0,
	attackrate = 0,
	attacklimit = 0,
	direction = math.random(1,8),
	exp = 10,
	attacklimit = 0,
	image = {
			"resources/greenfish.png" -- 1 - north
	},
	
	stateList = {
		attack = { 
			name = 'attack',
			actions = {
			  function(t) 
				if compare( (t.x - t.searchRange), (t.y - t.searchRange), (t.width  + t.searchRange) , (t.searchRange + t.height), hero.x, hero.y, hero.width, hero.height) == true then 
			      		if t.attacklimit < clock.second then
			    			t.attacklimit = clock.second + 1 * t.attackrate
						end
			    		if t.attackrate > 59 then 
							t.attackrate = t.attackrate - 60
				    		hero.hp = hero.hp - 2 
						end
			  		else
						t:changeState(t.stateList.hunt)
			    	end
				t:walk()

			 end
				}
			},

		hunt = { 
		  	name = 'hunt',
			actions = {
				function(t)
					if compare( (t.x - t.searchRange), (t.y - t.searchRange), (t.width  + t.searchRange) , (t.searchRange + t.height), hero.x, hero.y, hero.width, hero.height) == true then 
			  			t:changeState(t.stateList.attack)
			  		else
						if	t.x == hero.x and
							t.y > hero.y then t.direction = 1 --'north'
						elseif 	t.x < hero.x and
							t.y == hero.y then t.direction = 5 --'northeast'
						elseif 	t.x == hero.x and
							t.y < hero.y then t.direction = 2 --'east'
						elseif 	t.x > hero.x and
							t.y == hero.y then t.direction = 6 --'southeast'
						elseif 	t.x < hero.x and
							t.y > hero.y then t.direction = 3 --'south'
						elseif 	t.x < hero.x and
							t.y < hero.y then t.direction = 7 --'southwest'
						elseif 	t.x > hero.x and
							t.y < hero.y then t.direction = 4 --'west'
						elseif 	t.x > hero.x and
							t.y > hero.y then t.direction = 8 --'northwest'
						end
						t:walk()	
					end
				end
			}
		},

		idle = {
			name = 'idle',
		 	actions = {
				moveRandomly,
				-- search function for enemy's idle state
				function (t) -- checks if the monster is to hunt the hero
					if compare( (t.x - t.searchRange), (t.y - t.searchRange), (t.searchRange * 2 + t.width) , (t.searchRange * 2 + t.height), hero.x,hero.y, hero.width, hero.height) == true
					then 	
				    	t.currentState.process = "ending"
				    -- TODO: instead of line above use a changestate function, which clears tmp data and sets process of old state to 'starting'
					end	
				end
			}
	}
	}
}

		
dofile('monster.lua')
